package com.gz.controller;

import com.gz.aop.TokenHolder;
import com.gz.entity.PaperUser;
import com.gz.service.PaperUserService;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.gz.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.gz.dto.PaperUserDto;
import javax.servlet.http.HttpServletRequest;
/**
 * 试卷用户关系表(PaperUser)表控制层
 *
 * @author jhk
 * @since 2024-09-26 00:56:45
 */
@RestController
@RequestMapping("paperUser")
@Api(value = "paperUser控制层",tags = {"paperUser控制层"})
public class PaperUserController {
    /**
     * 服务对象
     */
    @Autowired
    private PaperUserService paperUserService;

    /**
     * 分页查询
     *
     * @param dto 筛选条件
     * @return 查询结果
     */
    @ApiOperation(value = "分页查询")
    @PostMapping("/queryPage")
    public R queryByPage(@RequestBody PaperUserDto dto, HttpServletRequest request) {
//        String token = TokenHolder.getToken();
        System.out.println("token-->"+dto.getToken());
        return R.ok(paperUserService.queryByPage(dto));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation(value = "主键查询")
    @GetMapping("/queryById")
    public R<PaperUser> queryById(@RequestParam("id") Integer id) {
        return R.ok(paperUserService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param paperUser 实体
     * @return 新增结果
     */
    @ApiOperation(value = "新增数据")
    @PostMapping("/save")
    public R<PaperUser> add(@RequestBody PaperUser paperUser) {
        return R.ok(paperUserService.insert(paperUser));
    }

    /**
     * 编辑数据
     *
     * @param paperUser 实体
     * @return 编辑结果
     */
    @ApiOperation(value = "编辑数据")
    @PostMapping("/update")
    public R<PaperUser> edit(@RequestBody PaperUser paperUser) {
        return R.ok(paperUserService.update(paperUser));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @GetMapping("/deleteById")
    @ApiOperation(value = "删除数据")
    public R<Boolean> deleteById(@RequestParam("id") Integer id) {
        return R.ok(paperUserService.deleteById(id));
    }

}

